/**
 * 
 */
package com.ez.supervise.service.impl;

import java.util.List;

import org.apache.commons.lang.math.NumberUtils;

import com.ez.supervise.core.Page;
import com.ez.supervise.dao.DemocracyGoalDao;
import com.ez.supervise.dao.DemocracyGoalSettingDao;
import com.ez.supervise.model.biz.DemocracyGoal;
import com.ez.supervise.model.biz.DemocracyGoalSetting;
import com.ez.supervise.model.biz.GoalDetail;
import com.ez.supervise.service.DemocracyGoalService;

/**
 * @author searph.wang
 * @email searph.wang@gmail.com
 * @Created at 2009-7-22
 * 
 */
public class DemocracyGoalServiceImpl implements DemocracyGoalService {
    private DemocracyGoalDao democracyGoalDao;
    private DemocracyGoalSettingDao democracyGoalSettingDao;

    // public int update(DemocracyGoal org) {
    // return sqlMapClientTemplate.update("sys.updateDemocracyGoal", org);
    // }

    public void setDemocracyGoalSettingDao(DemocracyGoalSettingDao democracyGoalSettingDao) {
        this.democracyGoalSettingDao = democracyGoalSettingDao;
    }

    public void setDemocracyGoalDao(DemocracyGoalDao democracyGoalDao) {
	this.democracyGoalDao = democracyGoalDao;
    }

    /*
     * (non-Javadoc)
     * 
     * @see com.ez.supervise.service.base.BaseService#delete(java.lang.Long)
     */
    public void delete(Long id) {
	democracyGoalDao.delete(id);
    }

    /*
     * (non-Javadoc)
     * 
     * @see com.ez.supervise.service.base.BaseService#insert(java.lang.Object)
     */
    public void insert(Object entity) {
	democracyGoalDao.insert(entity);

    }

    /*
     * (non-Javadoc)
     * 
     * @see com.ez.supervise.service.base.BaseService#update(java.lang.Object)
     */
    public void update(Object entity) {
	democracyGoalDao.update(entity);
    }

    /*
     * (non-Javadoc)
     * 
     * @see com.ez.supervise.service.base.BaseService#get(java.lang.Long)
     */
    public Object get(Long id) {
	return (DemocracyGoal) democracyGoalDao.get(id);
    }

    /*
     * (non-Javadoc)
     * 
     * @see com.ez.supervise.service.DemocracyGoalService#findAll()
     */
    public List findAll() {
	return democracyGoalDao.findAll();
    }

    /*
     * (non-Javadoc)
     * 
     * @see
     * com.ez.supervise.service.DemocracyGoalService#findDemocracyGoalByPage
     * (com.ez.supervise.core.Page)
     */
    public void findDemocracyGoalByPage(Page page) {
	page.setRoot(democracyGoalDao.findDemocracyGoalByPage(page));
	page.setTotalProperty(democracyGoalDao.findDemocracyGoalByCount(page));

    }

    /*
     * (non-Javadoc)
     * 
     * @see
     * com.ez.supervise.service.DemocracyGoalService#findSettingByPage(com.ez
     * .supervise.core.Page)
     */
    public void findSettingByPage(Page page) {
	page.setRoot(democracyGoalDao.findSettingByPage(page));
	page.setTotalProperty(democracyGoalDao.findSettingByCount(page));
    }

    /*
     * (non-Javadoc)
     * 
     * @see com.ez.supervise.service.DemocracyGoalService#save(java.lang.String,
     * java.lang.String)
     */
    public void save(String orgType, String goalIds) {
	String[] goalId = goalIds.split(",");
	DemocracyGoalSetting setting = null;
	for (String gId : goalId) {
	    if (NumberUtils.isNumber(gId)) {
		setting = new DemocracyGoalSetting(orgType, Long.valueOf(gId));
		int count = democracyGoalSettingDao.countExisSetting(setting);
		if (count == 0) {
		    democracyGoalSettingDao.insert(setting);
		}
	    }
	}

    }

    /* (non-Javadoc)
     * @see com.ez.supervise.service.DemocracyGoalService#deleteSetting(java.lang.Long)
     */
    public void deleteSetting(Long id) {
	democracyGoalSettingDao.delete(id);
    }

    /* (non-Javadoc)
     * @see com.ez.supervise.service.DemocracyGoalService#findDemocracyGoal(java.lang.Integer, java.lang.String)
     */
    public List<DemocracyGoal> findDemocracyGoal(Integer year, String orgType) {
	return democracyGoalDao.findDemocracyGoal(year, orgType);
    }
}
